//********************************//
//	     (c) McKay		  //   Do NOT copy or redistribute
//********************************//

--LAST EDITED 10.December.2010  16:13

--Minecraft SWEP version 2.2 [offline, garrysmod.org, multiplayer]
--This gets updated weekly, whereas the toybox minecraft swep gets updated daily (if)
--If you read this, you are awesome!

resource.AddFile( "models/mc_block.mdl" )
resource.AddFile( "models/mc_block.vvd" )
resource.AddFile( "models/mc_block.dx80.vtx" )
resource.AddFile( "models/mc_block.dx90.vtx" )
resource.AddFile( "models/mc_block.sw.vtx" )

//shared variables (should fix the clientconvar problem)
local debuginfo = 0
local firstspawn = 1
local curmat = 21
local swapattack = 0
local spawntype = 2
local blockhealth = 101
local blockcount = 0
local maxdistance = 270
local distancelimit = 0
local deletemconly = 1
local disablesounds = 0 //0 means on(only here)
local creator = ""
local crap = 1
local craps = 1
local delete = 0

SWEP.Author = "McKay"
SWEP.Contact        = "mckay@gmx.at"
SWEP.Purpose        = ""
SWEP.Instructions    = "Right-click to place a block, left click to destroy a block, press RELOAD to select block type!"

SWEP.WorldModel            = "models/mc_block.mdl"
SWEP.ViewModel            = "models/mc_block.mdl"
SWEP.HoldType = "Pistol"

SWEP.AdminSpawnable = true
SWEP.Spawnable 		= true

SWEP.Primary.ClipSize        = -1
SWEP.Primary.DefaultClip    = -1
SWEP.Primary.Automatic        = false
SWEP.Primary.Ammo            = "none"
SWEP.Secondary.ClipSize        = -1
SWEP.Secondary.DefaultClip    = -1
SWEP.Secondary.Automatic    = false
SWEP.Secondary.Ammo            = "none"
if (CLIENT) then
SWEP.Menudelay = 0
end

//Player = :GetAimVector()
local lastmat = 0
local vmcheck = 1
local IsWeapon = 1
local Mat = 0
local zpos = 0
local Blah = false
local Bleh = false
local ShootSound = Sound( "Concrete.ImpactHard" )
local BreakSound = Sound( "Breakable.Concrete" )
local Block = {
    "models/minecraft/adminium",    //1
    "models/minecraft/bloodstone",  //2
    "models/minecraft/bricks",      //3
    "models/minecraft/clay",        //4
    "models/minecraft/coal_ore",    //5
    "models/minecraft/cobblestone", //6
    "models/minecraft/creeper_mud", //7
    "models/minecraft/diamond_ore", //8
    "models/minecraft/dirt",        //9
    "models/minecraft/glass",       //10
    "models/minecraft/gold_ore",    //11
    "models/minecraft/gravel",      //12
    "models/minecraft/iron_ore",    //13
    "models/minecraft/lightstone",  //14
    "models/minecraft/mossy_cobblestone",//15
    "models/minecraft/obsidian",    //16
    "models/minecraft/redstone_ore",//17
    "models/minecraft/sand",        //18
    "models/minecraft/snow",        //19
    "models/minecraft/sponge",      //20
    "models/minecraft/stone",       //21
    "models/minecraft/wood_plank",  //22
    "models/minecraft/glass", //23
    "models/minecraft/ice",   //24
    "models/minecraft/bush",  //25
    "models/minecraft/iron",  //26
    "models/minecraft/gold",  //27
    "models/minecraft/diamond",//28
    "models/minecraft/wood",  //29
    "models/minecraft/tnt",   //30
    "models/minecraft/dirt_block",//31
    "models/minecraft/workbench", //32
    "models/minecraft/dirt_snow", //33
    "models/minecraft/pumpkin",   //34
    "models/minecraft/furnace",   //35
    "models/minecraft/chest",     //36
    "models/minecraft/bookshelf", //37
    "models/minecraft/mobspawner",//38
    "models/minecraft/jukebox",   //39
    "models/minecraft/water",     //40
    "models/minecraft/lava" }     //41

local BlockModel = {
    "models/minecraft/mc_rock.mdl", //1
    "models/minecraft/mc_zombieflesh.mdl", //2
    "models/minecraft/mc_rock.mdl", //3
    "models/minecraft/mc_sand.mdl", //4
    "models/minecraft/mc_rock.mdl", //5
    "models/minecraft/mc_rock.mdl", //6
    "models/minecraft/mc_mud.mdl", //7
    "models/minecraft/mc_rock.mdl", //8
    "models/minecraft/mc_dirt.mdl", //9
    "models/minecraft/mc_glass.mdl", //10
    "models/minecraft/mc_rock.mdl", //11
    "models/minecraft/mc_gravel.mdl", //12
    "models/minecraft/mc_rock.mdl", //13
    "models/minecraft/mc_glass.mdl", //14
    "models/minecraft/mc_rock.mdl", //15
    "models/minecraft/mc_rock.mdl", //16
    "models/minecraft/mc_rock.mdl", //17
    "models/minecraft/mc_sand.mdl", //18
    "models/minecraft/mc_snow.mdl", //19
    "models/minecraft/mc_foliage.mdl", //20
    "models/minecraft/mc_rock.mdl", //21
    "models/minecraft/mc_wood_plank.mdl", //22
    "models/minecraft/mc_glass.mdl", //23
    "models/minecraft/mc_glass.mdl", //24
    "models/minecraft/mc_grass.mdl", //25
    "models/minecraft/mc_metal_box.mdl", //26
    "models/minecraft/mc_metal_box.mdl", //27
    "models/minecraft/mc_metal_box.mdl", //28
    "models/minecraft/mc_wood_multiblock.mdl", //29
    "models/mc_tntblock.mdl", //30
    "models/minecraft/mc_grass_multiblock.mdl", //31
    "models/minecraft/mc_wood_multiblock.mdl", //32
    "models/minecraft/mc_snow_multiblock.mdl", //33
    "models/mc_pumpkin.mdl", //34 --------!!!
    "models/mc_furnace.mdl", //35 --------!!!
    "models/minecraft/mc_chest_multiblock.mdl", //36
    "models/minecraft/mc_wood_multiblock.mdl",  //37
    "models/minecraft/mc_metal_box.mdl",        //38
    "models/minecraft/mc_wood_multiblock.mdl",  //39
    "models/minecraft/mc_glass.mdl",            //40
    "models/minecraft/mc_gravel.mdl" }          //41
    
function SWEP:GetViewModelPosition( pos, ang )
    
    local Pos = Vector (-10,75,-50)
    ang:RotateAroundAxis( ang:Up(), -30 )
    ang:RotateAroundAxis( ang:Right(), 10 )
    

    local Right     = ang:Right()
        local Up         = ang:Up()
        local Forward     = ang:Forward()
    
        pos = pos + Pos.x * Right
        pos = pos + Pos.y * Forward
        pos = pos + Pos.z * Up


    return pos, ang
 
end

/*---------------------------------------------------------
Reload pops up the menu (sometimes reload() gets called twice, -> two fucking menus over each other)
---------------------------------------------------------*/
function SWEP:Reload()
if (CLIENT) then
    Bleh = true
    if (Blah == false) then
        Blah = true
		//Menu()
		if (firstspawn == 0 && tonumber(self.Menudelay) < CurTime()) then
			self:testpanel()
			self.Menudelay = tonumber(CurTime() + 0.1)
		end
		if (firstspawn == 1) then
			RunConsoleCommand("mc_firstinfo")
			firstspawn = 0
			self.Menudelay = tonumber(CurTime() + 0.1)
		end
    end
end
end

/*function Menu()
if (firstspawn == 0) then
	RunConsoleCommand("mc_menu");
end
if (firstspawn == 1) then
	RunConsoleCommand("mc_firstinfo")
	firstspawn = 0
end
end*/

/*---------------------------------------------------------
Think  & Material Think
---------------------------------------------------------*/
function SWEP:Think()  
if (CLIENT) then
    self:MatThink()
end
	 self:VMThink()
    if (vmcheck == 1) then //only exec the viewmodel:SetModel function when m_iMat changes (and not every think) to save performance
        self:ViewmodelThink()
        vmcheck = 0
    end
	if (CLIENT) then
    if (Bleh == false) then
        Blah = false
    end
	Bleh = false
	end
   // local VM = self:GetOwner():GetViewModel()
   // VM:SetMaterial( "models/shadertest/shader2" )

end

function SWEP:MatThink()
if (CLIENT) then
    if(!ValidEntity(self:GetOwner())) then return; end
    local VM = self:GetOwner():GetViewModel();
    //if not VM:IsValid() then return end

    if(!ValidEntity(VM)) then return; end // Just wait a while - it'll come back, eventually.
    self:SetNetworkedVar("m_iMat", GetConVar("cl_minecraft_blocktype"):GetInt());
    VM:SetMaterial( Block[self:GetMat()] )
end 
end

function SWEP:ViewmodelThink()
    if (!ValidEntity(self:GetOwner())) then return; end
    local VM = self:GetOwner():GetViewModel();
    if (!ValidEntity(VM)) then return; end
	local cl_mat = self:GetOwner():GetInfoNum("cl_minecraft_blocktype")
    if (cl_mat < 26 && cl_mat != -40) then
        VM:SetModel( "models/mc_block.mdl" )
    end
    if (cl_mat > 25) then
        VM:SetModel( "models/mc_multiblock.mdl" )
        end
    if (cl_mat == 40 || cl_mat == 41) then
		VM:SetModel( "models/mc_block.mdl")
    end
end

function SWEP:VMThink()
    if (lastmat != self:GetOwner():GetInfoNum("cl_minecraft_blocktype")) then
        vmcheck = 1
    end
    lastmat = self:GetOwner():GetInfoNum("cl_minecraft_blocktype")
end    

AccessorFuncNW(SWEP,"m_iMat","CurrentMat",0,FORCE_NUMBER)

function SWEP:GetMat()
    return self:GetNetworkedInt("m_iMat")
end
function SWEP:SetMat( matnumber )
    self:SetNetworkedVar("m_iMat", matnumber)
	curmat = matnumber
end

/*---------------------------------------------------------
    Main Attack Function
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
self:MasterReload()
local cl_swap = 0
if (CLIENT) then
	cl_swap = GetConVar("cl_minecraft_swapattack"):GetInt()
end
    if (swapattack > 0 || cl_swap == 1) then
        self:MCPrimaryAttack()
    end
    if (swapattack < 1 && cl_swap == 0) then
        self:MCSecondaryAttack()
    end
end
function SWEP:PrimaryAttack()
self:MasterReload()
local cl_swap = 0
if (CLIENT) then
	cl_swap = GetConVar("cl_minecraft_swapattack"):GetInt()
end
    if (swapattack > 0 || cl_swap == 1) then
        self:MCSecondaryAttack()
    end
    if (swapattack < 1 && cl_swap == 0) then
        self:MCPrimaryAttack()
    end
end


function SWEP:MCSecondaryAttack()
self:MasterReload()
	local ent = 0
    local tr = self.Owner:GetEyeTrace()
    local startpos = self.Owner:GetShootPos()
    local isBlock = false
    
    local tracedata = {}
    tracedata.start = startpos
    tracedata.endpos = tr.HitPos + tr.HitNormal * 16
    tracedata.filter = self.Owner
    
    local checktr = util.TraceLine(tracedata)
    if checktr.HitNonWorld then
        target = checktr.Entity
        if ( target ) then isBlock = true
        end
    end
    local checkent = 0
    local checkvec = Vector(0,0,0)
    if tr.HitNonWorld then
        checkent = tr.Entity
        checkvec = checkent:GetPos()
        if (debuginfo == 1) then print("checktr hit nonworld!") end
    end

    local SpawnPos = tr.HitPos + tr.HitNormal * 16
    
    local distvec = tr.HitPos - self.Owner:GetPos()
    local length = distvec:Length()
	
    if (distancelimit > 0) then
        if (length > maxdistance) then
            isBlock = true
        end
    end

    if ( isBlock == false ) then
	if (CLIENT) then
        if (GetConVar("cl_minecraft_disablesounds"):GetInt() < 1) then
		local rnd = math.random(3)
		if (rnd == 1) then
            		self:EmitSound( "physics/concrete/concrete_impact_hard1.wav" )
		end
		if (rnd == 2) then
			self:EmitSound( "physics/concrete/concrete_impact_hard2.wav" )
		end
		if (rnd == 3) then
			self:EmitSound( "physics/concrete/concrete_impact_hard3.wav" )
		end
        end
	end
    end
	
	if (CLIENT) then
        if (GetConVar("cl_minecraft_blocktype"):GetInt() > 41) then
            RunConsoleCommand("cl_minecraft_blocktype", "41")
            self:SetMat( 41 )
            print("no!")
        end
        if (GetConVar("cl_minecraft_blocktype"):GetInt() < 1) then
            RunConsoleCommand("cl_minecraft_blocktype", "1")
            self:SetMat( 1 )
            print(">:(")
        end
	end
    
    // The rest is only done on the server
    if (!SERVER) then return end
	
    if ( isBlock == false && tr.HitWorld == false && spawntype == 2) then
        
        //check wether we are placing on top, bottom, or the four sides
        local hitz = tr.HitPos.z
        local checkvecz = checkvec.z
        local hmc = hitz - checkvecz   //hmc should be about '16' when placing on top OR on bottom
 
        if (hitz < 0) then
            hitz = - hitz
        end
        if (checkvecz <0) then
            checkvecz = - checkvecz
        end
        local hmc2 = hitz - checkvecz
        if (hmc2 < 0) then
            hmc2 = - hmc2
        end
        
        local toporbottom = 0
        if (hmc2 > 15.9 && hmc2 < 16.1) then // top OR bottom
            if (hmc < 0) then
                toporbottom = 2
                if (debuginfo == 1) then print("bottom = " .. tostring(toporbottom)) end
            end
            if (hmc > 0) then
                toporbottom = 1
                if (debuginfo == 1) then print("top = " .. tostring(toporbottom)) end
            end
        end
        
        if (toporbottom == 0) then  //one of the four sides
            if (tr.HitPos.z > checkvec.z) then
                zpos = math.floor( SpawnPos.z / 32 ) * 32 + 0
                if (debuginfo == 1) then print("upper half") end
            end
            if (tr.HitPos.z < checkvec.z) then
                zpos = math.floor( SpawnPos.z / 32 ) * 32 + 32
                if (debuginfo == 1) then print("lower half") end
            end
        end
        
        if (toporbottom == 1) then //top
            zpos = math.floor( SpawnPos.z / 32 ) * 32 + 32
            if ((SpawnPos.z - zpos) < -1) then // bug!
                zpos = math.floor( SpawnPos.z / 32) * 32 + 0
            end
            if (debuginfo == 2) then print("top->SpawnPos.z = " .. tostring(SpawnPos.z)) end
            if (debuginfo == 2) then print("top->zpos = " .. tostring(zpos)) end
        end
        
        if (toporbottom == 2) then //bottom
            zpos = math.floor( SpawnPos.z / 32 ) * 32 + 0
            if ((SpawnPos.z - zpos) > 1) then // bug!
                zpos =math.floor( SpawnPos.z / 32 ) * 32 + 32
            end
            if (debuginfo == 2) then print("bottom->SpawnPos.z = " .. tostring(SpawnPos.z)) end
            if (debuginfo == 2) then print("bottom->zpos = " .. tostring(zpos)) end
        end
        
        if (debuginfo == 1) then print("isBlock == false!!, checkvec.z = " .. tostring(checkvec.z)) end
        if (debuginfo == 1) then print("HitPos.z = " .. tostring(tr.HitPos.z)) end
    end
    
    if ( isBlock == true) then //block is blocking the way
        if (debuginfo == 1) then print("isBlock is true!") end
    end
    if ( tr.HitWorld == true && isBlock == false && spawntype == 2) then  //no block nearby
        zpos = math.floor( SpawnPos.z / 32 ) * 32 + 0
        if (debuginfo == 1) then print("tr.HitWorld !!!! && isBlock == false!") end
    end  
    
    if ( isBlock == false ) then  //pos is ok, block can be created
            if (curmat != 40 && curmat != 41) then
			if (SERVER) then
				if (curmat != 30) then
                ent = ents.Create( "prop_minecraftblock" )
				else
				ent = ents.Create( "prop_physics" )
				end
			end
                lavaorwater = 0
            else
                ent = ents.Create( "prop_waterized" )
                local damping, density, buoyancy
                if (curmat == 40) then //water
                    damping = 15
                    density = 70
                    buoyancy = 600
                    lavaorwater = 0
                end
                if (curmat == 41) then //lava
                    damping = 40
                    density = 90
                    buoyancy = 300
                    lavaorwater = 1
                end
                MakeWaterizedProp( ent, self:GetOwner(), damping, density, buoyancy )
            end
			
            //local SpawnPos = tr.HitPos + tr.HitNormal * 16
            local xpos = math.floor( SpawnPos.x / 32 ) * 32 + 16
            local ypos = math.floor( SpawnPos.y / 32 ) * 32 + 16
        if (spawntype == 1) then
            zpos = math.floor( SpawnPos.z / 32 ) * 32 + 16
        end
        if (spawntype == 0) then
            zpos = SpawnPos.z
        end
		if (SERVER) then
			//GetUsermessage();
			creator = self:GetOwner():Nick()
			if (curmat != 30) then //no for tnt
			ent:SetCreator( self:GetOwner():Nick() )
			end
            ent:SetModel( BlockModel[tonumber(curmat)])
            ent:SetMaterial( Block[tonumber(curmat)] )
            ent:SetPos( Vector( xpos, ypos, zpos) )
            //ent:PhysicsInitBox( SpawnPos + Vector( -16, -16, -16 ), SpawnPos + Vector(  16,  16,  16 ) )
            ent:SetKeyValue( "DisableShadows", "1" )
            ent:SetKeyValue( "targetname", "mcblock" )
            ent:SetKeyValue( "spawnflags", 8 ) //disable movement!
        end
		//ent:SetPos( Vector( xpos, ypos, zpos) )
		//ent:SetKeyValue( "spawnflags", 8 )
		if (SERVER) then
        if (blockhealth < 0 && curmat != 40 && curmat != 41 && curmat != 30) then
            //local filter = "FiltreDegats"
            //ent:Fire("setdamagefilter", filter, 0) //unbreakable
			ent:SetMyHealth( -100002 )
        end
		end
		if (curmat != 30 && blockhealth > 0) then   //tnt has its own health
		if (SERVER) then
			if ( curmat != 40 && curmat != 41 ) then
				ent:SetMyHealth( blockhealth )
			end
		end
        end

            //print("spawnflags set")
            //ent:SetHealth( 100 )
            //ent:SetKeyValue( "sethealth", GetConVar("minecraft_blockhealth"):GetInt() )  
			if (SERVER) then
            ent:Spawn()
			end
if (SERVER) then
        undo.Create("MC Block")
            undo.AddEntity( ent )
            undo.SetPlayer( self.Owner )
			undo.SetCustomUndoText("Undone Minecraft Block")
            undo.Finish()
    end
end
end
/*---------------------------------------------------------
    MCSecondaryAttack
---------------------------------------------------------*/

function SWEP:MCPrimaryAttack()
self:MasterReload()
    local tr = self.Owner:GetEyeTrace()
        local distvec = tr.HitPos - self.Owner:GetPos()
        local length = distvec:Length()

if (distancelimit < 1) then
    if tr.HitNonWorld then
        target = tr.Entity  
        if (target) then
			if (CLIENT) then
				if (GetConVar("cl_minecraft_disablesounds"):GetInt() < 1) then
					local rnd = math.random(2)
					if (rnd == 1 ) then
						self:EmitSound( "physics/concrete/concrete_break3.wav" )
					else
						self:EmitSound( "physics/concrete/concrete_break2.wav" )
					end
				end
            end
            self:ShootEffects( self )
    
    local effectdata = EffectData()
        effectdata:SetOrigin( tr.HitPos )
        effectdata:SetNormal( tr.HitNormal )
        effectdata:SetMagnitude( 8 )
        effectdata:SetScale( 1 )
        effectdata:SetRadius( 16 )
        util.Effect( "GlassImpact", effectdata )
        end
    end
    // The rest is only done on the server
    if (!SERVER) then return end
    
    local trace = self.Owner:GetEyeTrace();
    if( not trace.HitWorld ) then // if you hit an entity
        if (ValidEntity(trace.Entity) && trace.Entity:IsPlayer() == false) then
			if (trace.Entity:GetClass() == "prop_minecraftblock" || trace.Entity:GetClass() == "prop_waterized") then
				if (trace.Entity:GetCreator() == self:GetOwner():Nick()) then
					trace.Entity:Remove()
				end
		   end
		    if (trace.Entity:GetName() == "mcblock" && trace.Entity:GetModel() == "models/mc_tntblock.mdl") then
				trace.Entity:Remove()
			end
        end
    end
end

if (distancelimit > 0) then
if (length < maxdistance) then
    if tr.HitNonWorld then
         target = tr.Entity  
         if (target) then
			if (CLIENT) then
				if (GetConVar("cl_minecraft_disablesounds"):GetInt() < 1) then
					local rnd = math.random(2)
					if (rnd == 1 ) then
						self:EmitSound( "physics/concrete/concrete_break3.wav" )
					else
						self:EmitSound( "physics/concrete/concrete_break2.wav" )
					end
				end
            end
            self:ShootEffects( self )
     
     local effectdata = EffectData()
         effectdata:SetOrigin( tr.HitPos )
         effectdata:SetNormal( tr.HitNormal )
         effectdata:SetMagnitude( 8 )
         effectdata:SetScale( 1 )
         effectdata:SetRadius( 16 )
         util.Effect( "GlassImpact", effectdata )
        end
    end      
     // The rest is only done on the server
     if (!SERVER) then return end
     
     local trace = self.Owner:GetEyeTrace();
     if( not trace.HitWorld ) then // if you hit an entity
        if (ValidEntity(trace.Entity) && trace.Entity:IsPlayer() == false) then
			if (trace.Entity:GetClass() == "prop_minecraftblock" || trace.Entity:GetClass() == "prop_waterized") then
				if (trace.Entity:GetCreator() == self:GetOwner():Nick()) then
					trace.Entity:Remove()
				end
		   end
		   if (trace.Entity:GetName() == "mcblock" && trace.Entity:GetModel() == "models/mc_tntblock.mdl") then
				trace.Entity:Remove()
			end
        end
     end    
end
end
end

    
   
/*---------------------------------------------------------
   Name: ShouldDropOnDie
   Desc: Should this weapon be dropped when its owner dies?
---------------------------------------------------------*/
function SWEP:OnRemove()
if (CLIENT) then
    if(ValidEntity(self:GetOwner())) then
        local VM = self:GetOwner():GetViewModel();
    //if not VM:IsValid() then return end
        if(ValidEntity(VM)) then
            VM:SetMaterial("");
        end
    end
    IsWeapon = 0
end
end
function SWEP:ShouldDropOnDie()
    return false
end

function SWEP:Holster()
    if(ValidEntity(self:GetOwner())) then
	if (CLIENT) then
        local VM = self:GetOwner():GetViewModel();
        if(ValidEntity(VM)) then
            VM:SetMaterial("");
        end
    end
	end
    IsWeapon = 0
    return true
end

function SWEP:Deploy()
    //self:SendWeaponAnim(ACT_VM_DRAW)
    if (debuginfo == 1 ) then print("block deploy()!!!!") end
    IsWeapon = 1
	self:MasterReload()
    self:ViewmodelThink()
    return true
end


function removeall()
if (SERVER) then
	for k, v in pairs( ents.GetAll() ) do
		if ( v:IsValid() ) then
		//if (SERVER) then
			if ( v:GetName() == "mcblock" ) then
				v:Remove()
			end
		//end
		end
	end
end
end
concommand.Add("minecraft_removeallblocks", removeall)

function MakeWaterizedProp( ent, ply, damping, density, buoyancy )
    -- Generic stufff
    if not ent:IsValid() then return end
    --duplicator.DoGeneric( ent, Data )
    ent:SetPlayer( ply )
    ent:Spawn()
    --duplicator.DoGenericPhysics( ent, ply, Data )

    -- Custom data
    ent:SetDamping( damping )
    ent.damping = damping
    ent:SetDensity( density )
    ent.density = density
    ent:SetBuoyancy( buoyancy )
    ent.buoyancy = buoyancy
	
    return ent
end

duplicator.RegisterEntityClass( "prop_waterized", MakeWaterizedProp, "damping", "density", "buoyancy", "Data" )

if (CLIENT) then
function optionspanel()
    local options = vgui.Create("DFrame")
	options:SetMouseInputEnabled(true)
	options:SetKeyboardInputEnabled(true)
    options:SetPos(550, 320)
    options:SetSize(250, 250)
    options:SetTitle( "Options" )
    options:SetVisible( true )
    options:MakePopup()
    
    local swap = vgui.Create( "DCheckBoxLabel", options )
    swap:SetParent( options )
    swap:SetPos( 10,30 ) //10/36
    swap:SetText( "Swap destroy/create mouse buttons" )
    swap.OnChange = function(chkBox)
        if (swap:GetChecked() == true) then
            RunConsoleCommand("cl_minecraft_swapattack", "1")
        end
        if (swap:GetChecked() == false) then
            RunConsoleCommand("cl_minecraft_swapattack", "0")
        end
    end    
    if (GetConVar("cl_minecraft_swapattack"):GetInt() > 0) then
        swap:SetValue( 1 )
    end
    if (GetConVar("cl_minecraft_swapattack"):GetInt() < 1) then
        swap:SetValue( 0 )
    end
    swap:SizeToContents()
    
    local ds = vgui.Create( "DCheckBoxLabel", options )
    ds:SetParent( options )
    ds:SetPos( 10,50 ) //y + 20
    ds:SetText( "Disable sounds" )
    ds.OnChange = function(chkBox)
        if (ds:GetChecked() == true) then
            RunConsoleCommand("cl_minecraft_disablesounds", "1")
        end
        if (ds:GetChecked() == false) then
            RunConsoleCommand("cl_minecraft_disablesounds", "0")
        end
    end    
    if (GetConVar("cl_minecraft_disablesounds"):GetInt() > 0) then
        ds:SetValue( 1 )
    end
    if (GetConVar("cl_minecraft_disablesounds"):GetInt() < 1) then
        ds:SetValue( 0 )
    end
    ds:SizeToContents()
    
    /*local mo = vgui.Create( "DCheckBoxLabel", options )
    mo:SetParent( options )
    mo:SetPos( 10,70 ) //y + 20
    mo:SetText( "Only delete Minecraft blocks" )
    mo.OnChange = function(chkBox)
        if (mo:GetChecked() == true) then
            RunConsoleCommand("cl_minecraft_deletemconly", "1")
        end
        if (mo:GetChecked() == false) then
            RunConsoleCommand("cl_minecraft_deletemconly", "0")
        end
    end    
    if (GetConVar("cl_minecraft_deletemconly"):GetInt() > 0) then
        mo:SetValue( 1 )
    end
    if (GetConVar("cl_minecraft_deletemconly"):GetInt() < 1) then
        mo:SetValue( 0 )
    end
    mo:SizeToContents()*/
    
    local dl = vgui.Create( "DCheckBoxLabel", options )
    dl:SetParent( options )
    dl:SetPos( 10,96 ) //y + 20
    dl:SetText( "Distance limit" )
    dl.OnChange = function(chkBox)
        if (dl:GetChecked() == true) then
            RunConsoleCommand("cl_minecraft_distancelimit", "1")
        end
        if (dl:GetChecked() == false) then
            RunConsoleCommand("cl_minecraft_distancelimit", "0")
        end
    end    
    if (GetConVar("cl_minecraft_distancelimit"):GetInt() > 0) then
        dl:SetValue( 1 )
    end
    if (GetConVar("cl_minecraft_distancelimit"):GetInt() < 1) then
        dl:SetValue( 0 )
    end
    dl:SizeToContents()
    
    local NumSlider = vgui.Create( "DNumSlider", options )
    NumSlider:SetPos( 106,75 )
    NumSlider:SetWide( 130 )
    NumSlider:SetText( "" )
    NumSlider:SetMin( 0 ) -- Minimum number of the slider
    NumSlider:SetMax( 1000 ) -- Maximum number of the slider
    NumSlider:SetDecimals( 0 ) -- Sets a decimal. Zero means it's a whole number
    NumSlider:SetConVar( "cl_minecraft_maxspawndist" ) -- Set the convar  
    
    local bh = vgui.Create( "DCheckBoxLabel", options )
    bh:SetParent( options )
    bh:SetPos( 10,133 ) //y + 20
    bh:SetText( "Block health" )
    local lasthealth = 0
    bh.OnChange = function(chkBox)
        if (bh:GetChecked() == true) then
            lasthealth = GetConVar("cl_minecraft_blockhealth"):GetInt()
            if (lasthealth < 0) then
                lasthealth = 101
            end
            RunConsoleCommand("cl_minecraft_blockhealth", tostring(lasthealth))
        end
        if (bh:GetChecked() == false) then
            RunConsoleCommand("cl_minecraft_blockhealth", "-1") //invincible blocks
        end
    end    
    if (GetConVar("cl_minecraft_blockhealth"):GetInt() > 0) then
        bh:SetValue( 1 )
    end
    if (GetConVar("cl_minecraft_blockhealth"):GetInt() < 0) then
        bh:SetValue( 0 )
    end
    bh:SizeToContents()
    
    local NumSlider2 = vgui.Create( "DNumSlider", options )
    NumSlider2:SetPos( 106,112 )
    NumSlider2:SetWide( 130 )
    NumSlider2:SetText( "" )
    NumSlider2:SetMin( -1 ) -- Minimum number of the slider
    NumSlider2:SetMax( 999 ) -- Maximum number of the slider
    NumSlider2:SetDecimals( 0 ) -- Sets a decimal. Zero means it's a whole number
    NumSlider2:SetConVar( "cl_minecraft_blockhealth" ) -- Set the convar
    NumSlider2.OnValueChanged = function (pSelf, fValue)
        if (fValue < "0") then
            bh:SetValue(0)
        end
        if (fValue > "0") then
            bh:SetValue(1)
        end
        RunConsoleCommand("cl_minecraft_blockhealth", tostring(fValue))
    end

    local lav1 = vgui.Create( "DCheckBoxLabel", options )
    lav1:SetParent( options )
    lav1:SetPos( 10,159 ) //y + 20
    lav1:SetText( "Lava ignites the player" )
    lav1.OnChange = function(chkBox)
        if (lav1:GetChecked() == true) then
            RunConsoleCommand("cl_minecraft_lavaigniteplayer", "1")
        end
        if (lav1:GetChecked() == false) then
            RunConsoleCommand("cl_minecraft_lavaigniteplayer", "0")
        end
    end    
    if (GetConVar("cl_minecraft_lavaigniteplayer"):GetInt() > 0) then
        lav1:SetValue( 1 )
    end
    if (GetConVar("cl_minecraft_lavaigniteplayer"):GetInt() < 1) then
        lav1:SetValue( 0 )
    end
    lav1:SizeToContents()
    
    /*local lav2 = vgui.Create( "DCheckBoxLabel", options )
    lav2:SetParent( options )
    lav2:SetPos( 10,179 ) //y + 20
    lav2:SetText( "Lava ignites other blocks" )
    lav2.OnChange = function(chkBox)
         if (lav2:GetChecked() == true) then
            RunConsoleCommand("minecraft_lavaigniteblocks", "1")
         end
         if (lav2:GetChecked() == false) then
            RunConsoleCommand("minecraft_lavaigniteblocks", "0")
         end
     end    
    if (GetConVar("cl_minecraft_lavaigniteblocks"):GetInt() > 0) then
         lav2:SetValue( 1 )
     end
    if (GetConVar("cl_minecraft_lavaigniteblocks"):GetInt() < 1) then
         lav2:SetValue( 0 )
     end
     lav2:SizeToContents()*/
   
    local tomenu = vgui.Create("DButton")
    tomenu:SetParent( options )
    tomenu:SetText( "Close" )
    tomenu:SetPos( 90, 210 )
    tomenu:SetSize( 80, 30 )
    tomenu.DoClick = function ( btn ) //when the button is clicked
        options:Close()
    end
end
end

if (CLIENT) then
function infopanel()
    local info = vgui.Create("DFrame")
	info:SetMouseInputEnabled(true)
	info:SetKeyboardInputEnabled(true)
    info:SetPos(550,320) -- set the frame's position on the screen
    info:SetSize(250, 300) -- set the frame size 543, 228
    info:SetTitle( "Minecraft Swep - Beta v3.1" ) -- set the frame title
    info:SetVisible( true ) -- Make the frame visible
    info:MakePopup() -- make the frame popup
   
    local  info1 = vgui.Create("DLabel", info)
    info1:SetText("Important stuff:")
    info1:SetPos(86, 24)
    info1:SizeToContents()
    
    local  info2 = vgui.Create("DLabel", info)
    info2:SetText("--- This is the multiplayer version! [SVN]")
    info2:SetPos(10, 48)
    info2:SizeToContents()
    
    local  info20 = vgui.Create("DLabel", info)
    info20:SetText("- Right click a block type for faster switching")
    info20:SetPos(10, 64)
    info20:SizeToContents()
    
    local  info3 = vgui.Create("DLabel", info)
    info3:SetText("- Blocks are destructible")
    info3:SetPos(10, 80)
    info3:SizeToContents()
    
    local  info4 = vgui.Create("DLabel", info)
    info4:SetText("- Added lava and water blocks (ignite, extinguish)")
    info4:SetPos(10, 96)
    info4:SizeToContents()
    
    local  info5 = vgui.Create("DLabel", info)                   
    info5:SetText("  (you can swim in them, try jumping)")
    info5:SetPos(10, 112)
    info5:SizeToContents()
    
    local  info6 = vgui.Create("DLabel", info)
    info6:SetText("Please report any bugs you find!")
    info6:SetPos(10, 134)
    info6:SizeToContents()
    
    
    
    local  info7 = vgui.Create("DLabel", info)
    info7:SetText("Also available for singleplayer!")
    info7:SetPos(10, 160)
    info7:SizeToContents()
    
    local  info8 = vgui.Create("DLabel", info)
    info8:SetText(" ") //upper middle
    info8:SetPos(10, 182)
    info8:SizeToContents()
    
    local  info9 = vgui.Create("DLabel", info)
    info9:SetText(" ") //lower middle
    info9:SetPos(10, 196)
    info9:SizeToContents()
    
    local  info11 = vgui.Create("DLabel", info)
    info11:SetText("This panel will only show up once")
    info11:SetPos(10, 230)
    info11:SizeToContents()
    
    local tomenu = vgui.Create("DButton")
    tomenu:SetParent( info )
    tomenu:SetText( "Close" )
    tomenu:SetPos( 90, 260 )
    tomenu:SetSize( 80, 30 )
    tomenu.DoClick = function ( btn ) //when the button is clicked
        info:Close()
    end
end
end

if (CLIENT) then
function SWEP:testpanel() -- spawn menu (for blocks)
	menucheck = 1
	craps = craps +1
	blockcount = 0
	RunConsoleCommand("cl_minecraft_z_blockcount", tostring(craps))
	if (craps > 20) then
		craps = 1
	end
    local test = vgui.Create("DFrame") -- Create the frame
	test:SetMouseInputEnabled(true)
	test:SetKeyboardInputEnabled(true)
    local removemenu = vgui.Create("DButton")
    local options = vgui.Create("DButton")
    //more than 1940 blocks = crash
      
    /*local infolabel = vgui.Create( "DLabel", test )
    infolabel:SetText("Blocks: " .. tostring(blockcount))
    infolabel:SetPos( 485, 367 ) //485/344
    if (blockcount > 999) then
        infolabel:SetPos( 478, 344 )
    end
    infolabel:SizeToContents()*/
    
    removemenu:SetParent( test ) -- parent the button to the frame
    removemenu:SetText( "Remove" ) -- set the button text
    removemenu:SetPos(415 , 364) -- 482, 316
    removemenu:SetSize( 50, 20 ) -- set the button size
    removemenu.DoClick = function ( btn ) -- this will be called when the button is clicked
                local menu123 = DermaMenu() -- create a derma menu
                menu123:AddOption("Remove ALL blocks", function()
                // Msg("Removed all minecraft blocks!")
                blockcount = 0
                //infolabel:SetText("Blocks: " .. tostring(blockcount))
                //RunConsoleCommand("ent_remove_all", "mcblock")
				crap = crap +1
				RunConsoleCommand("cl_minecraft_playerfix", tostring(crap))
				crap = crap -1
				RunConsoleCommand("cl_minecraft_playerfix", tostring(crap))
                end )
                menu123:Open()
        end  -- ending the doclick function
    
    options:SetParent( test ) -- parent the button to the frame
    options:SetText( "Options" ) -- set the button text
    options:SetPos(345 , 364) -- 348, 364
    options:SetSize( 55, 20 ) -- set the button size
    options.DoClick = function ( btn ) -- this will be called when the button is clicked
        RunConsoleCommand("mc_options")
        end  -- ending the doclick function
    
    local spawntype = vgui.Create( "DCheckBoxLabel", DermaPanel )
    spawntype:SetParent( test )
    spawntype:SetPos( 10,367 ) //130/367
    spawntype:SetText( "Uncheck/Check if blocks spawn underground/floating!" )
    spawntype.OnChange = function(chkBox)
        if (spawntype:GetChecked() == true) then
            RunConsoleCommand("cl_minecraft_spawntype", "2")
        end
        if (spawntype:GetChecked() == false) then
            RunConsoleCommand("cl_minecraft_spawntype", "1")
        end
    end    
    if (GetConVar("cl_minecraft_spawntype"):GetInt() == 2) then
        spawntype:SetValue( 1 )
    end
    if (GetConVar("cl_minecraft_spawntype"):GetInt() == 1) then
        spawntype:SetValue( 0 )
    end
    spawntype:SizeToContents()


//-----------FIRST ROW----------//    
    local stone = vgui.Create("DImageButton", test)
    stone:SetMaterial( "VGUI/minecraft/stone_spawn" )
    stone:SizeToContents()
    stone:SetPos(5,25)
    stone.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "21");
    end
    stone.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "21");
        test:Close();
    end

    local cobblestone = vgui.Create("DImageButton", test)
    cobblestone:SetMaterial( "VGUI/minecraft/cobblestone_spawn" )
    cobblestone:SizeToContents()
    cobblestone:SetPos(72,25)
    cobblestone.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "6");
    end
    cobblestone.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "6");
        test:Close();
    end
    
    local mcobblestone = vgui.Create("DImageButton", test)
    mcobblestone:SetMaterial( "VGUI/minecraft/mossy_cobblestone_spawn" )
    mcobblestone:SizeToContents()
    mcobblestone:SetPos(139,25)
    mcobblestone.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "15");
    end
    mcobblestone.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "15");
        test:Close();
    end
 
    local ad = vgui.Create("DImageButton", test)
    ad:SetMaterial( "VGUI/minecraft/adminium_spawn" )
    ad:SizeToContents()
    ad:SetPos(206,25)
    ad.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "1");
    end
    ad.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "1");
        test:Close()
    end

    local gr = vgui.Create("DImageButton", test)
    gr:SetMaterial( "VGUI/minecraft/gravel_spawn" )
    gr:SizeToContents()
    gr:SetPos(273,25)
    gr.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "12");
    end
    gr.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "12");
        test:Close()
    end    

    local di = vgui.Create("DImageButton", test)
    di:SetMaterial( "VGUI/minecraft/dirt_spawn" )
    di:SizeToContents()
    di:SetPos(340,25)
    di.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "9");
    end
    di.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "9");
        test:Close()
    end    

    local cl = vgui.Create("DImageButton", test)
    cl:SetMaterial( "VGUI/minecraft/clay_spawn" )
    cl:SizeToContents()
    cl:SetPos(407,25)
    cl.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "4");
    end
    cl.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "4");
        test:Close()
    end    

    local sa = vgui.Create("DImageButton", test)
    sa:SetMaterial( "VGUI/minecraft/sand_spawn" )
    sa:SizeToContents()
    sa:SetPos(474,25)
    sa.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "18");
    end
    sa.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "18");
        test:Close()
    end
//-----------SECOND ROW---------//
    local co = vgui.Create("DImageButton", test)
    co:SetMaterial( "VGUI/minecraft/coal_ore_spawn" )
    co:SizeToContents()
    co:SetPos(5,92)
    co.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "5");
    end  
    co.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "5");
        test:Close()
    end

    local ir = vgui.Create("DImageButton", test)
    ir:SetMaterial( "VGUI/minecraft/iron_ore_spawn" )
    ir:SizeToContents()
    ir:SetPos(72,92)
    ir.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "13");
    end  
    ir.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "13");
        test:Close()
    end   
    
    local re = vgui.Create("DImageButton", test)
    re:SetMaterial( "VGUI/minecraft/redstone_ore_spawn" )
    re:SizeToContents()
    re:SetPos(139,92)
    re.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "17");
    end  
    re.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "17");
        test:Close()
    end    
    
    local dia = vgui.Create("DImageButton", test)
    dia:SetMaterial( "VGUI/minecraft/diamond_ore_spawn" )
    dia:SizeToContents()
    dia:SetPos(206,92)
    dia.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "8");
    end  
    dia.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "8");
        test:Close()
    end    
    
    local go = vgui.Create("DImageButton", test)
    go:SetMaterial( "VGUI/minecraft/gold_ore_spawn" )
    go:SizeToContents()
    go:SetPos(273,92)
    go.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "11");
    end  
    go.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "11");
        test:Close()
    end
    
    local ob = vgui.Create("DImageButton", test)
    ob:SetMaterial( "VGUI/minecraft/obsidian_spawn" )
    ob:SizeToContents()
    ob:SetPos(340,92)
    ob.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "16");
    end  
    ob.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "16");
        test:Close()
    end
    
    local sp = vgui.Create("DImageButton", test)
    sp:SetMaterial( "VGUI/minecraft/sponge_spawn" )
    sp:SizeToContents()
    sp:SetPos(407,92)
    sp.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "20");
    end  
    sp.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "20");
        test:Close()
    end    
    
    local sn = vgui.Create("DImageButton", test)
    sn:SetMaterial( "VGUI/minecraft/snow_spawn" )
    sn:SizeToContents()
    sn:SetPos(474,92)
    sn.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "19");
    end  
    sn.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "19");
        test:Close()
    end            
//-----------------THIRD ROW--------------//
    local br = vgui.Create("DImageButton", test)
    br:SetMaterial( "VGUI/minecraft/bricks_spawn" )
    br:SizeToContents()
    br:SetPos(5,159)
    br.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "3");
    end  
    br.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "3");
        test:Close()
    end    
    
    local wo = vgui.Create("DImageButton", test)
    wo:SetMaterial( "VGUI/minecraft/wood_plank_spawn" )
    wo:SizeToContents()
    wo:SetPos(72,159)
    wo.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "22");
    end  
    wo.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "22");
        test:Close()
    end
    
    local bl = vgui.Create("DImageButton", test)
    bl:SetMaterial( "VGUI/minecraft/bloodstone_spawn" )
    bl:SizeToContents()
    bl:SetPos(139,159)
    bl.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "2");
    end  
    bl.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "2");
        test:Close()
    end
    
    local li = vgui.Create("DImageButton", test)
    li:SetMaterial( "VGUI/minecraft/lightstone_spawn" )
    li:SizeToContents()
    li:SetPos(206,159)
    li.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "14");
    end  
    li.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "14");
        test:Close()
    end
    
    local cr = vgui.Create("DImageButton", test)
    cr:SetMaterial( "VGUI/minecraft/creeper_mud_spawn" )
    cr:SizeToContents()
    cr:SetPos(273,159)
    cr.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "7");
    end  
    cr.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "7");
        test:Close()
    end
    
    local gl = vgui.Create("DImageButton", test)
    gl:SetMaterial( "VGUI/minecraft/glass_spawn" )
    gl:SizeToContents()
    gl:SetPos(340,159)
    gl.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "23");
    end  
    gl.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "23");
        test:Close()
    end
    
    local ice = vgui.Create("DImageButton", test)
    ice:SetMaterial( "VGUI/minecraft/ice_spawn" )
    ice:SizeToContents()
    ice:SetPos(407,159)
    ice.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "24");
    end  
    ice.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "24");
        test:Close()
    end
    
    local tnt = vgui.Create("DImageButton", test)
    tnt:SetMaterial( "VGUI/minecraft/tnt_spawn" )
    tnt:SizeToContents()
    tnt:SetPos(474,159)
    tnt.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "30");
    end  
    tnt.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "30");
        test:Close()
    end
//-------------------FOURTH ROW--------------------//
    local iro = vgui.Create("DImageButton", test)
    iro:SetMaterial( "VGUI/minecraft/iron_spawn" )
    iro:SizeToContents()
    iro:SetPos(5,226)
    iro.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "26");
    end  
    iro.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "26");
        test:Close()
    end
    
    local gol = vgui.Create("DImageButton", test)
    gol:SetMaterial( "VGUI/minecraft/gold_spawn" )
    gol:SizeToContents()
    gol:SetPos(72,226)
    gol.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "27");
    end  
    gol.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "27");
        test:Close()
    end
    
    local diam = vgui.Create("DImageButton", test)
    diam:SetMaterial( "VGUI/minecraft/diamond_spawn" )
    diam:SizeToContents()
    diam:SetPos(139,226)
    diam.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "28");
    end  
    diam.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "28");
        test:Close()
    end
    
    local woo = vgui.Create("DImageButton", test)
    woo:SetMaterial( "VGUI/minecraft/wood_spawn" )
    woo:SizeToContents()
    woo:SetPos(206,226)
    woo.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "29");
    end  
    woo.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "29");
        test:Close()
    end
    
    local wor = vgui.Create("DImageButton", test)
    wor:SetMaterial( "VGUI/minecraft/workbench_spawn" )
    wor:SizeToContents()
    wor:SetPos(273,226)
    wor.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "32");
    end  
    wor.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "32");
        test:Close()
    end
    
    local ds = vgui.Create("DImageButton", test)
    ds:SetMaterial( "VGUI/minecraft/dirt_snow_spawn" )
    ds:SizeToContents()
    ds:SetPos(340,226)
    ds.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "33");
    end  
    ds.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "33");
        test:Close()
    end
    
    local db = vgui.Create("DImageButton", test)
    db:SetMaterial( "VGUI/minecraft/dirt_block_spawn" )
    db:SizeToContents()
    db:SetPos(407,226)
    db.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "31");
    end  
    db.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "31");
        test:Close()
    end
    
    local fn = vgui.Create("DImageButton", test)
    fn:SetMaterial( "VGUI/minecraft/furnace_spawn" )
    fn:SizeToContents()
    fn:SetPos(474,226)
    fn.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "35");
    end  
    fn.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "35");
        test:Close()
    end
//-------------------FIFTH ROW---------------------//    
    local bu = vgui.Create("DImageButton", test)
    bu:SetMaterial( "VGUI/minecraft/bush_spawn" )
    bu:SizeToContents()
    bu:SetPos(5,293)
    bu.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "25");
    end  
    bu.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "25");
        test:Close()
    end
    
    local pk = vgui.Create("DImageButton", test)
    pk:SetMaterial( "VGUI/minecraft/pumpkin_spawn" )
    pk:SizeToContents()
    pk:SetPos(72,293)
    pk.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "34");
    end  
    pk.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "34");
        test:Close()
    end
    
    local che = vgui.Create("DImageButton", test)
    che:SetMaterial( "VGUI/minecraft/chest_spawn" )
    che:SizeToContents()
    che:SetPos(139,293)
    che.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "36");
    end  
    che.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "36");
        test:Close()
    end
    
    local bok = vgui.Create("DImageButton", test)
    bok:SetMaterial( "VGUI/minecraft/bookshelf_spawn" )
    bok:SizeToContents()
    bok:SetPos(206,293)
    bok.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "37");
    end  
    bok.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "37");
        test:Close()
    end
    
    local mob = vgui.Create("DImageButton", test)
    mob:SetMaterial( "VGUI/minecraft/mobspawner_spawn" )
    mob:SizeToContents()
    mob:SetPos(273,293)
    mob.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "38");
    end  
    mob.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "38");
        test:Close()
    end
    
    local jb = vgui.Create("DImageButton", test)
    jb:SetMaterial( "VGUI/minecraft/jukebox_spawn" )
    jb:SizeToContents()
    jb:SetPos(340,293)
    jb.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "39");
    end  
    jb.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "39");
        test:Close()
    end

    local wat = vgui.Create("DImageButton", test)
    wat:SetMaterial( "VGUI/minecraft/water_spawn" )
    wat:SizeToContents()
    wat:SetPos(407,293)
    wat.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "40");
    end  
    wat.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "40");
        test:Close()
    end
    
    local lav = vgui.Create("DImageButton", test)
    lav:SetMaterial( "VGUI/minecraft/lava_spawn" )
    lav:SizeToContents()
    lav:SetPos(474,293)
    lav.DoClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "41");
    end  
    lav.DoRightClick = function()
        RunConsoleCommand("cl_minecraft_blocktype", "41");
        test:Close()
    end
    
    test:SetPos(350,250) -- set the frame's position on the screen
    test:SetSize(543, 390) -- set the frame size 543, 228
    test:SetTitle( "Block Types" ) -- set the frame title
    test:SetVisible( true ) -- Make the frame visible
    test:MakePopup() -- make the frame popup
end -- ending the function
end

if (SERVER) then //used for delete
function GetPlayer(player, commandName, args) //this is the 'removeallmyblocks' function
	curplayer = ""
	curplayer = player:Nick()
	RunConsoleCommand("minecraft_removeallmyblocks")
end
concommand.Add("minecraft_getplayer", GetPlayer)
function GetPlayer2(player, commandName, args)
	for k, v in pairs( ents.GetAll() ) do
		if ( v:IsValid() ) then
		//if (v:GetOwner() == curplayer) then
			if ( v:GetClass() == "prop_minecraftblock" || v:GetClass() == "prop_waterized" ) then
				if (v:GetCreator() == player:Nick()) then
					v:Remove()
				end
			end
		//end
		end
	end
end
concommand.Add("minecraft_getcurplayer", GetPlayer2)
function GetBlockCount(player, commandName, args)
blockcount = 0
    for k, v in pairs( ents.GetAll() ) do
        if ( v:IsValid()) then
			if ( v:GetClass() == "prop_minecraftblock" || v:GetClass() == "prop_waterized" ) then
				if ( v:GetCreator() == player:Nick() ) then
					blockcount = blockcount + 1
				end
			end
        end
    end
end
concommand.Add("minecraft_getblockcount", GetBlockCount)
function removeallplayer(player, commandName, args)
	for k, v in pairs( ents.GetAll() ) do
		if ( v:IsValid() ) then
		//if (v:GetOwner() == curplayer) then
			if ( v:GetClass() == "prop_minecraftblock" || v:GetClass() == "prop_waterized" ) then
				if (v:GetCreator() == player:Nick()) then
					v:Remove()
				end
			end
		//end
		end
	end
end
concommand.Add("minecraft_removeallmyblocks", removeallplayer)
end
if (SERVER) then
function SWEP:DeleteMyBlocks()
	for k, v in pairs( ents.GetAll() ) do
		if ( v:IsValid() ) then
		//if (v:GetOwner() == curplayer) then
			if ( v:GetClass() == "prop_minecraftblock" || v:GetClass() == "prop_waterized" ) then
				if (v:GetCreator() == self:GetOwner():Nick()) then
					v:Remove()
				end
			end
		//end
		end
	end
end
end

function SWEP:MasterReload()
if (SERVER) then
	curmat = tonumber(self:GetOwner():GetInfoNum("cl_minecraft_blocktype"))
	maxdistance = tonumber(self:GetOwner():GetInfoNum("cl_minecraft_maxspawndist"))
	deletemconly = tonumber(self:GetOwner():GetInfoNum("cl_minecraft_deletemconly"))
	disablesounds = tonumber(self:GetOwner():GetInfoNum("cl_minecraft_disablesounds"))
	distancelimit = tonumber(self:GetOwner():GetInfoNum("cl_minecraft_distancelimit"))
	spawntype = tonumber(self:GetOwner():GetInfoNum("cl_minecraft_spawntype"))
	swapattack = tonumber(self:GetOwner():GetInfoNum("cl_minecraft_swapattack"))
	blockhealth = tonumber(self:GetOwner():GetInfoNum("cl_minecraft_blockhealth"))
end
if (CLIENT) then
	craps = craps +1
	//RunConsoleCommand("minecraft_playerfix", tostring(craps))
	if (craps > 20) then
		craps = 1
	end
end
end

if (CLIENT) then
//concommand.Add("mc_menu", testpanel) -- adding the console command
concommand.Add("mc_firstinfo", infopanel) //info panel for all of you who are too stupid to read the fucking description
concommand.Add("mc_options", optionspanel)
end